const install = (Vue, vm) => {
	
	const isLogin = () =>{
		
		const token = vm.vuex_token
		if(!token){
			
			//getCurrentPages获取当前页面栈的实例		
			const currentPage = getCurrentPages().pop()
			// 获取页面路径和请求参数
			const {options, route} = currentPage
			console.log(currentPage);
			// Object.keys 返回所有可枚举的内容
			const optionsKeys = Object.keys(options)
			console.log(optionsKeys);
			let params = ''
			if (optionsKeys.length > 0){
				params = optionsKeys.reduce((pre, current)=> {
					return `${pre}${current}=${options[current]}&`
				}, '?').slice(0, -1)
			}

			uni.setStorageSync('back_url', route + params)
			
			vm.$u.toast("请登录")
			setTimeout(() => {
				vm.$u.route({
					type: 'redirect',
					url: '/pages/auth/login',
				})
			}, 1500)
			
			return false
		}
		vm.$u.toast("欢迎你")
		return true
	}
	
	//更新用户数据
	const updateUser = async()=> {
		const userInfo = await vm.$u.api.userInfo()
		vm.$u.vuex('vuex_user', userInfo)
	}
	
	vm.$u.utils = {
		isLogin,
		updateUser
	}

}

export default {
	install
}